<template>
  <view class="test-container">
    <view class="test-section">
      <text class="test-title">ParkMap 测试页面</text>
      
      <view class="test-item">
        <text class="test-label">API测试:</text>
        <button @click="testAPI" class="test-btn">测试API连接</button>
        <text class="test-result">{{ apiResult }}</text>
      </view>
      
      <view class="test-item">
        <text class="test-label">数据测试:</text>
        <button @click="testData" class="test-btn">测试数据处理</button>
        <text class="test-result">{{ dataResult }}</text>
      </view>
      
      <view class="test-item">
        <text class="test-label">跳转测试:</text>
        <button @click="goToParkMap" class="test-btn">跳转到ParkMap</button>
      </view>
    </view>
  </view>
</template>

<script>
import { API } from '@/utils/api.js'
import { processImageUrls } from '@/utils/url-helper.js'

export default {
  data() {
    return {
      apiResult: '未测试',
      dataResult: '未测试'
    }
  },
  methods: {
    async testAPI() {
      try {
        this.apiResult = '测试中...'
        const res = await API.park.getAreaList({})
        console.log('API测试结果:', res)
        this.apiResult = 'API连接成功: ' + JSON.stringify(res).substring(0, 100) + '...'
      } catch (error) {
        console.error('API测试失败:', error)
        this.apiResult = 'API连接失败: ' + error.message
      }
    },
    
    testData() {
      try {
        const testData = {
          parkName: '测试园区',
          thumbnailUrl: '/test.jpg',
          warehouseTypes: [{ typeName: '高标仓' }]
        }
        const processed = processImageUrls(testData)
        console.log('数据处理结果:', processed)
        this.dataResult = '数据处理成功: ' + JSON.stringify(processed).substring(0, 100) + '...'
      } catch (error) {
        console.error('数据处理失败:', error)
        this.dataResult = '数据处理失败: ' + error.message
      }
    },
    
    goToParkMap() {
      uni.navigateTo({
        url: '/pages/parkMap/parkMap'
      })
    }
  }
}
</script>

<style scoped>
.test-container {
  padding: 40rpx;
  background: #f5f5f5;
  min-height: 100vh;
}

.test-section {
  background: white;
  border-radius: 16rpx;
  padding: 40rpx;
}

.test-title {
  font-size: 36rpx;
  font-weight: bold;
  color: #333;
  margin-bottom: 40rpx;
  display: block;
}

.test-item {
  margin-bottom: 30rpx;
  padding: 20rpx;
  background: #f8f9fa;
  border-radius: 12rpx;
}

.test-label {
  font-size: 28rpx;
  color: #666;
  margin-bottom: 16rpx;
  display: block;
}

.test-btn {
  background: #007aff;
  color: white;
  border: none;
  border-radius: 8rpx;
  padding: 16rpx 32rpx;
  font-size: 26rpx;
  margin-bottom: 16rpx;
}

.test-result {
  font-size: 24rpx;
  color: #333;
  line-height: 1.5;
  display: block;
}
</style>
